﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace FileManagerSystem.Extend
{
    /// <summary>
    /// 功能描述:列表集合扩展
    /// </summary>
    public static class IEnumerableExtend
    {
        /// <summary>
        /// 把数组转为逗号连接的字符串
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public static string ArrayToString(this IEnumerable collection)
        {
            string resStr = "";
            foreach (var item in collection)
            {
                if (resStr != "")//第二个开始操作
                {
                    resStr += ",";
                }
                resStr += item;
            }
            return resStr;
        }

        /// <summary>
        /// 把数组转为split分割后连接的字符串
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="split"></param>
        /// <returns></returns>
        public static string ArrayToString(this IEnumerable collection, string split)
        {
            string resStr = "";
            if (split.IsNullOrEmpty())
            {
                split = ",";
            }
            foreach (var item in collection)
            {
                if (resStr != "")//第二个开始操作
                {
                    resStr += split;
                }
                resStr += item;
            }
            return resStr;
        }
    }
}
